package com.pig4cloud.pig.yu.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.pig4cloud.pig.buyan.entity.CarModel;
import com.pig4cloud.pig.buyan.entity.Style;
import com.pig4cloud.pig.qc.entity.LabelEntity;
import com.pig4cloud.pig.yu.entity.CarBrandEntity;
import com.pig4cloud.pig.yu.entity.CarInfoEntity;
import com.pig4cloud.pig.yu.mapper.CarInfoMapper;
import com.pig4cloud.pig.yu.service.CarInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.List;

/**
 * 车辆信息管理
 */
@Service
public class CarInfoServiceImpl extends ServiceImpl<CarInfoMapper, CarInfoEntity> implements CarInfoService {

	@Autowired
	private CarInfoMapper carInfoMapper;
	@Override
	public boolean existsByCarCode(String carCode) {
		LambdaQueryWrapper<CarInfoEntity> wrapper = Wrappers.lambdaQuery();
		wrapper.eq(CarInfoEntity::getCarCode, carCode);
		return this.count(wrapper) > 0;
	}
	@Override
	public IPage<CarInfoEntity> getCarInfoPage(Page<CarInfoEntity> page, CarInfoEntity carInfo, BigDecimal minPrice,
											   BigDecimal maxPrice) {

		return carInfoMapper.selectCarInfoPage(page,
				carInfo.getBrandId(),
				carInfo.getModelId(),
				carInfo.getStatus(),
				minPrice,
				maxPrice,
				carInfo.getLableId());
	}

	@Override
	public List<CarBrandEntity> getBrands(String series) {
		return baseMapper.selectBrands(series);
	}

	@Override
	public List<CarModel> getModels(Long brandId) {
		return baseMapper.selectModels(brandId);
	}

	@Override
	public List<Style> getStyles(Long modelId) {
		return baseMapper.selectStyles(modelId);
	}


	@Override
	public List<LabelEntity> getAllLabel() {
		return carInfoMapper.selectAllLabel();
	}

	@Override
	public boolean updateById(CarInfoEntity entity) {
		return super.updateById(entity);
	}

	@Override
	public CarInfoEntity getCarInfoById(Long infoId) {
		return this.getBaseMapper().getCarInfoById(infoId);
	}
}